package io.renren.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.stereotype.Component;

/**
 * @author :
 * @version V1.0
 * @Project:
 * @Package
 * @Description: spring environment上下文获取工具类
 * @date Date :
 **/
@Slf4j
@Component
@Lazy(false)
public class EnvironmentHelper implements EnvironmentAware {
    private Environment environment;
    //商用环境
    public static final String PROD = "prod";
    //测试环境
    private static final String TEST = "test";
    //开发环境
    private static final String DEV = "dev";

    /**
     * 是否为商用(生产)环境
     * @return
     */
    public boolean isProd() {
        return environment.acceptsProfiles(Profiles.of(PROD));
    }
    /**
     * 是否为开发环境
     * @return
     */
    public boolean isDev() {
        return environment.acceptsProfiles(Profiles.of(DEV));
    }
    /**
     * 是否为测试环境
     * @return
     */
    public boolean isTest() {
        return environment.acceptsProfiles(Profiles.of(TEST));
    }

    /**
     * 获取当前环境
     * @return
     */
    public String[] getActiveProfiles() {
        return environment.getActiveProfiles();
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment=environment;
    }
}
